package com.hszl.blog.controller;

import com.hszl.blog.common.aop.LogAnnotation;
import com.hszl.blog.service.ArticleService;
import com.hszl.blog.vo.Result;
import com.hszl.blog.vo.params.ArticleParam;
import com.hszl.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 胡爽
 * @date: 2022/5/19 18:40
 **/
@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    @LogAnnotation(module = "文章",operation = "获取文章列表")
    public Result articles(@RequestBody PageParams pageParams){
        //int m = 10/0;

        return articleService.listArticlesPage(pageParams);
    }
    @PostMapping("hot")
    public Result hot(){
        int limit = 5;
        return articleService.hotArticles(limit);
    }
    @PostMapping("new")
    public Result newArticles(){
        int limit = 5;
        return articleService.newArticles(limit);
    }

    @PostMapping("listArchives")
    public Result Archives(){
        return articleService.getArchives();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){

        return articleService.findArticleById(articleId);
    }

    @PostMapping("publish")
    public Result writeArticle(@RequestBody ArticleParam articleParam){

        return articleService.writeArticle(articleParam);
    }
}
